<template>
	<BaseContainer
		class="report-table-wrapper"
		v-loading="loading"
		element-loading-text="加载中..."
		element-loading-background="rgba(255, 255, 255, 0.8)"
	>
		<div class="t-header tc w-100">
			<p class="tc">南京市养老机构综合运营补贴自查报告</p>
		</div>
		<ReportTable
			:column="dataListBase"
			:isDetail="isDetail"
			:moreNewsModel="moreNewsModel"
			:baseModel="baseModel"
			:model="modelData"
			@change="handleSave"
		></ReportTable>
		<ReportTable
			:column="dataListSelf"
			:isDetail="isDetail"
			:moreNewsModel="moreNewsModel"
			:baseModel="baseModel"
			:model="modelData"
			@change="handleSave"
		></ReportTable>
		<ReportTable
			:column="dataListApply"
			:isDetail="isDetail"
			:moreNewsModel="moreNewsModel"
			:baseModel="baseModel"
			:model="modelData"
			@change="handleSave"
		>
			<template v-slot:note>
				<p>本机构承诺以上数据资料属实，如有不实，愿承担相关处罚。</p>
				<div class="w-100 tr padding">
					<p>负责人签名： （单位盖章）</p>
					<p style="padding-right: 3vw">年 月 日</p>
				</div>
			</template>
		</ReportTable>

    <OrgArchives ref="orgArchivesEl"></OrgArchives>
	</BaseContainer>
</template>

<script setup lang="ts">
import OrgArchives from './OrgArchives/index.vue'
import ReportTable from './ReportTable/index.vue'
import apiMod from '@/apiMod'
import { filterEmptyObj } from '@/utils/util'

const props = defineProps<{
	creditCode?: string | number
	params?: any
	editData?: any
	isDetail?: boolean
	caseId?: string | number
	custome?: boolean
	approvalStatus?: string | number
}>()
const emit = defineEmits(['save'])
const orgArchivesEl = ref(null)
const baseModel = shallowRef({})

const modelData = ref({})
const loading = ref(false)
const moreNewsModel: any = ref({})

const dataListBase = [
	[
		{
			m: '基 本 情 况',
			bl: 1,
			fs: 16,
			mc: {
				rs: 1,
				cs: 5,
			},
		},
	],
	[
		{
			m: '机构名称',
			style: { width: '200px' },
			mc: {
				rs: 1,
				cs: 1,
			},
		},
		{
			m: '',
			prop: 'organizationName',
			linkType: true,
			setColor: true,
			showLink: (col, model) => {
				orgArchivesEl.value?.getServiceOrgInfo(model.creditCode)
			},
		},
		{ m: '法定代表人', style: { width: '200px' } },
		{
			m: '',
			setColor: true,
			prop: 'legalUserName',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
	],
	[
		{ m: '机构地址' },
		{
			m: '',
			setColor: true,
			prop: 'organizationAddress',
			mc: {
				rs: 1,
				cs: 1,
			},
		},
		{ m: '邮政编码' },
		{
			m: '',
			setColor: true,
			prop: 'postalCode',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
	],
	[
		{ m: '联系人' },
		{
			m: '',
			setColor: true,
			prop: 'burdenUserName',
		},
		{ m: '联系电话' },
		{
			m: '',
			setColor: true,
			prop: 'burdenUserPhone',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
	],
	[
		{ m: '营业执照（民非）证号' },
		{ setColor: true, m: '', prop: 'orgHomeLicense' },
		{ m: '机构设置证号（备案）' },
		{ setColor: true, m: '', prop: 'filingCode' },
	],
	[
		{ m: '核定床位数' },
		{ setColor: true, m: '', prop: 'approvedBedTotal' },
		{ m: '入住老人数' },
		{
			m: '',
			setColor: true,
			prop: 'checkinOldmanNum',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
	],
]
const dataListSelf = [
	[
		{
			m: '自 查 情 况',
			bl: 1,
			fs: 16,
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 10,
			},
		},
	],
	[
		{ m: '自查时间' },
		{ m: '', prop: 'selfCheckDate' },
		{ m: '自查方式' },
		{ m: '', prop: 'selfCheckWay' },
		{
			m: '参与人数',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
		{ m: '', prop: 'partakeNum' },
		{
			m: '参与比例',
			align: 'center',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
		{ m: '', prop: 'partakeRate' },
	],
	[
		{
			m: '自查内容',
			style: {
				width: '80px',
				padding: '40px',
			},
			mc: {
				rs: 5,
				cs: 1,
			},
		},
		{
			m: '1.是否存在虚假广告宣传',
			align: 'left',
			mc: {
				rs: 1,
				cs: 3,
			},
		},
		{ m: '是' },
		{ m: '', prop: 'unrealPublicityFlagLabel', type: 'radio', v: '是' },
		{ m: '否' },
		{ m: '', prop: 'unrealPublicityFlagLabel', type: 'radio', v: '否' },
		{ m: '备注' },
		{ m: '', prop: 'unrealPublicityNote' },
	],
	[
		{
			m: '2.是否按照协议提供服务',
			align: 'left',
			mc: {
				rs: 1,
				cs: 3,
			},
		},
		{ m: '是' },
		{ m: '', prop: 'agreementServiceFlagLabel', type: 'radio', v: '是' },
		{ m: '否' },
		{ m: '', prop: 'agreementServiceFlagLabel', type: 'radio', v: '否' },
		{ m: '备注' },
		{ m: '', prop: 'agreementServiceNote' },
	],
	[
		{
			m: '3.是否侵害老人合法权益',
			align: 'left',
			mc: {
				rs: 1,
				cs: 3,
			},
		},
		{ m: '是' },
		{ m: '', prop: 'infringementFlagLabel', type: 'radio', v: '是' },
		{ m: '否' },
		{ m: '', prop: 'infringementFlagLabel', type: 'radio', v: '否' },
		{ m: '备注' },
		{ m: '', prop: 'managerCertificateNumber' },
	],
	[
		{
			m: '4.老人对机构的综合评价',
			align: 'left',
			mc: {
				rs: 1,
				cs: 3,
			},
		},
		{ m: '满意' },
		{ m: '', prop: 'comprehensiveEvaluationLabel', type: 'radio', v: '满意' },
		{ m: '基本满意' },
		{ m: '', prop: 'comprehensiveEvaluationLabel', type: 'radio', v: '基本满意' },
		{ m: '不 满 意' },
		{ m: '', prop: 'comprehensiveEvaluationLabel', type: 'radio', v: '不满意' },
	],
	[
		{
			m: '5.其他事项',
			align: 'left',
			mc: {
				rs: 1,
				cs: 3,
			},
		},
		{ m: '', prop: 'otherThings1' },
		{ m: '', prop: 'otherThings2' },
		{ m: '', prop: 'otherThings3' },
		{ m: '', prop: 'otherThings4' },
		{ m: '', prop: 'otherThings5' },
		{ m: '', prop: 'otherThings6' },
	],
	[
		{
			m: '存在问题',
			align: 'left',
			mc: {
				rs: 5,
				cs: 1,
			},
		},
		{
			m: '',
			index: '1.',
			prop: 'questionOption1',
			align: 'left',
			mc: {
				rs: 1,
				cs: 9,
			},
		},
	],
	[
		{
			m: '',
			index: '2.',
			prop: 'questionOption2',
			align: 'left',
			mc: {
				rs: 1,
				cs: 9,
			},
		},
	],
	[
		{
			m: '',
			index: '3.',
			prop: 'questionOption3',
			align: 'left',
			mc: {
				rs: 1,
				cs: 9,
			},
		},
	],
	[
		{
			m: '',
			index: '4.',
			prop: 'questionOption4',
			align: 'left',
			mc: {
				rs: 1,
				cs: 9,
			},
		},
	],
	[
		{
			m: '',
			index: '5.',
			prop: 'questionOption5',
			align: 'left',
			mc: {
				rs: 1,
				cs: 9,
			},
		},
	],
	[
		{
			m: '自查结论',
		},
		{
			m: '非常满意',
		},
		{ m: '', prop: 'selfCheckResultLabel', type: 'radio', v: '非常满意' },
		{
			m: '基本满意',
		},
		{ m: '', prop: 'selfCheckResultLabel', type: 'radio', v: '基本满意' },
		{
			m: '不满意',
		},
		{ m: '', prop: 'selfCheckResultLabel', type: 'radio', v: '不满意' },
		{
			m: '满意率',
		},
		{
			m: '',
			prop: 'selfCheckResultRate',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
	],
]

const applyConfigBase = [
	[
		{
			m: '调查员签名',
			bl: 1,
			fs: 16,
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 8,
			},
		},
	],
	[
		{
			m: '姓名',
		},
		{
			m: '',
			style: {
				width: '200px',
			},
			prop: 'investigatorName',
		},
		{
			m: '职务',
		},
		{
			m: '',
			prop: 'investigatorDuty',
			style: {
				width: '200px',
			},
		},
		{
			m: '姓名',
		},
		{
			m: '',
			prop: 'investigatorName2',
		},
		{
			m: '职务',
		},
		{
			m: '',
			prop: 'investigatorDuty2',
		},
	],
	[
		{
			m: '被调查人签名',
			bl: 1,
			fs: 16,
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 8,
			},
		},
	],
	[
		{
			m: '',
			prop: 'selfSign1',
		},
		{
			m: '',
			prop: 'selfSign2',
		},
		{
			m: '',
			prop: 'selfSign3',
		},
		{
			m: '',
			prop: 'selfSign4',
		},
		{
			m: '',
			prop: 'selfSign5',
		},
		{
			m: '',
			prop: 'selfSign6',
		},
		{
			m: '',
			prop: 'selfSign7',
		},
		{
			m: '',
			prop: 'selfSign8',
		},
	],
	[
		{
			m: '',
			prop: 'selfSign9',
		},
		{
			m: '',
			prop: 'selfSign10',
		},
		{
			m: '',
			prop: 'selfSign11',
		},
		{
			m: '',
			prop: 'selfSign12',
		},
		{
			m: '',
			prop: 'selfSign13',
		},
		{
			m: '',
			prop: 'selfSign14',
		},
		{
			m: '',
			prop: 'selfSign15',
		},
		{
			m: '',
			prop: 'selfSign16',
		},
	],
	[
		{
			m: '',
			prop: 'selfSign17',
		},
		{
			m: '',
			prop: 'selfSign18',
		},
		{
			m: '',
			prop: 'selfSign19',
		},
		{
			m: '',
			prop: 'selfSign20',
		},
		{
			m: '',
			prop: 'selfSign21',
		},
		{
			m: '',
			prop: 'selfSign22',
		},
		{
			m: '',
			prop: 'selfSign23',
		},
		{
			m: '',
			prop: 'selfSign24',
		},
	],
	[
		{
			m: '',
			prop: 'selfSign25',
		},
		{
			m: '',
			prop: 'selfSign26',
		},
		{
			m: '',
			prop: 'selfSign27',
		},
		{
			m: '',
			prop: 'selfSign28',
		},
		{
			m: '',
			prop: 'selfSign29',
		},
		{
			m: '',
			prop: 'selfSign30',
		},
		{
			m: '',
			prop: 'selfSign31',
		},
		{
			m: '',
			prop: 'selfSign32',
		},
	],
	[
		{
			prop: 'note',
			mc: {
				rs: 1,
				cs: 9,
			},
		},
	],
]
const dataListApply = ref([...applyConfigBase])

const getInitData = async () => {
	const params = props.params || {}
	const query = {
		year: '',
		month: '',
		creditCode: props.creditCode,
		projectId: props.params.subsidyProjectId,
	}
	if (params.belongDate) {
		query.year = params.belongDate.replace('年', '-').replace('月', '').split('-')[0]
		query.month = params.belongDate.replace('年', '-').replace('月', '').split('-')[1]
	} else {
		return
	}
	modelData.value = props.editData

	try {
		const condition = (props.caseId && props.isDetail) || props.custome || props.approvalStatus == -2
		loading.value = true
		const uptoData = await apiMod.view_metadata_self(query).then((res) => res.data)
		loading.value = false
		const reportData = condition ? props.editData : uptoData
		let baseData = Object.freeze({ ...reportData })

		moreNewsModel.value = {}

		if (uptoData.dataContent) {
			moreNewsModel.value = {
				...uptoData.dataContent,
				viewStatus: uptoData.viewStatus,
			}
		} else {
			moreNewsModel.value = {
				...uptoData,
				...baseData,
			}
		}
		baseModel.value = baseData

		const mixData = {
			...uptoData,
			...props.editData,
		}
		if (!condition) {
			modelData.value = {
				...props.editData,
				...filterEmptyObj(uptoData),
			}
		} else {
			modelData.value = mixData
		}
		if (!condition) handleSave()
	} catch (error) {
		loading.value = false
	}
}
onMounted(() => {
	if (props.params) getInitData()
})
const handleSave = () => {
	emit('save', modelData.value, 'report_1002', props.editData)
}
onUnmounted(() => {
	// emit('save', modelData.value, 'report_1002',props.editData)
})
</script>

<style scoped lang="scss">
.report-table-wrapper {
	width: 100%;
	margin: 0 auto;
	padding: 10px 30px;
	top: 0;

	.t-header {
		text-align: center;
		font-size: 18px;
		font-weight: bold;
		padding: 15px 0;

		.text-sm {
			font-weight: 400;
			font-size: 16px;
		}
	}
}
</style>
